using DG.Tweening;
using System.Collections;
using UnityEngine;

public class GoldController : MonoBehaviour
{
	private GameObject TotalGold;

	public bool isMagnet;

	public int _value;

	private void Start()
	{
		GetComponent<Rigidbody2D>().AddForce(new Vector2(UnityEngine.Random.Range(-0.5f, 0.5f), UnityEngine.Random.Range(0.6f, 0.8f)) * UnityEngine.Random.Range(20, 30));
		UnityEngine.Object.Destroy(base.gameObject, 8f);
		Invoke("CoinSapMat", 5f);
	}

	private void Update()
	{
		if (isMagnet)
		{
			CoinFly();
		}
	}

	private void CoinSapMat()
	{
		StartCoroutine(CoinNhapNhay());
		Invoke("CoinSapMat", 0.5f);
	}

	private IEnumerator CoinNhapNhay()
	{
		GetComponent<tk2dSprite>().color = new Color(1f, 1f, 1f, 0.6f);
		yield return new WaitForSeconds(0.2f);
		GetComponent<tk2dSprite>().color = new Color(1f, 1f, 1f, 1f);
	}

	private void CoinFly()
	{
		TotalGold = GameObject.FindGameObjectWithTag("TotalGold");
		base.transform.DOMove(TotalGold.transform.position, UnityEngine.Random.Range(0.3f, 0.7f)).OnComplete(CoinMoveFinish);
	}

	private void CoinMoveFinish()
	{
		GameManager.TotalCoin += _value;
		GameManager.TotalgoldStage += _value;
		UnityEngine.Object.Destroy(base.gameObject);
	}
}
